package com.fact.actions;

import java.util.ArrayList;
import java.util.Map;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.fact.dto.NodeAttributeDTO;
import com.fact.dto.SegmentDTO;
import com.fact.models.SegmentService;
import com.fact.utils.AppConstant;

public class NodeAttribute extends BaseAction implements SessionAware{
	
private static final long serialVersionUID = 1L;
	
	private Map<String,Object> session;
	private String page=AppConstant.NODE_ATTRIBUTE;
	private String pageTitle="FMtool - Node Attribute";
	private String opType;	
	ArrayList<SegmentDTO> segmentList=new ArrayList<SegmentDTO>();
	ArrayList<NodeAttributeDTO> attributeList=new ArrayList<NodeAttributeDTO>();
	
	SegmentService segmentService=new  SegmentService();
	NodeAttributeService nodeAttributeService=new NodeAttributeService();
	int kpiId;
	
	private ArrayList<NodeAttributeDTO> attribute;
	
	public String nodeAttributeHome()
	{
		if(opType==null || (!opType.equalsIgnoreCase("save") && !opType.equalsIgnoreCase("delete") && !opType.equalsIgnoreCase("edit")))
			this.session.put("operation_message", null);
	
		segmentList=segmentService.getSegmentList();
		return SUCCESS;
	}
	public String nodeAttributeList()
	{
		attributeList=nodeAttributeService.getAtributeList(kpiId);	
		return SUCCESS;
	}
	public String updateNodeAttribute()
	{
		segmentList=segmentService.getSegmentList();
		boolean response=nodeAttributeService.updateNodeAttributes(attribute);
		if(response==false)
		{
			addActionMessage("Error in Attribute Update Operation.");
			return INPUT;
		}
		else
		{
			this.session.put("operation_message","Attribute Successfully Updated.");
			return SUCCESS;
		}
	}
	
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public String getPageTitle() {
		return pageTitle;
	}
	public void setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
	}
	public String getOpType() {
		return opType;
	}
	public void setOpType(String opType) {
		this.opType = opType;
	}
	
	
	public ArrayList<NodeAttributeDTO> getAttributeList() {
		return attributeList;
	}
	public void setAttributeList(ArrayList<NodeAttributeDTO> attributeList) {
		this.attributeList = attributeList;
	}
	public ArrayList<SegmentDTO> getSegmentList() {
		return segmentList;
	}
	public void setSegmentList(ArrayList<SegmentDTO> segmentList) {
		this.segmentList = segmentList;
	}
	public void setSession(Map<String, Object> session) 
	{
		this.session = session;
	}
	public ServletContext getServletContext()
	{
		return ServletActionContext.getServletContext();
	}
	public int getKpiId() {
		return kpiId;
	}
	public void setKpiId(int kpiId) {
		this.kpiId = kpiId;
	}
	public ArrayList<NodeAttributeDTO> getAttribute() {
		return attribute;
	}
	public void setAttribute(ArrayList<NodeAttributeDTO> attribute) {
		this.attribute = attribute;
	}
	
}